package com.googlecode.cnasort.cc.rmi.client.core;

import com.googlecode.cnasort.cc.rmi.common.data.RMIFileDir;
import com.googlecode.cnasort.cc.rmi.common.data.RMIFileDirFilter;

public abstract class FileLoaderClientCoreFilters
{
    private RMIFileDirFilter directoryFilter;
    private RMIFileDirFilter fileFilter;

    public FileLoaderClientCoreFilters()
    {
        this.directoryFilter = new RMIFileDirFilter()
        {
            @Override
            public boolean accept( RMIFileDir folder ) {
                String filename = folder.getName();

                for( String ignore : getDirectoryFilterIgnoreList() ) {
                    if( filename.equals( ignore ) ) {
                        return false;
                        }
                    }

                for( String ignore : getDirectoryFilterIgnoreStartsWithList() ) {
                    if( filename.startsWith( ignore ) ) {
                        return false;
                        }
                    }

                return true;
            }
        };
        this.fileFilter = new RMIFileDirFilter()
        {
            @Override
            public boolean accept(RMIFileDir file)
            {
                String filename = file.getName();

                for( String ignore : getFileFilterIgnoreEndsWithList() ) {
                    if( filename.endsWith( ignore ) ) {
                        return false;
                        }
                    }

                return true;
            }
        };
    }

    abstract public Iterable<String> getFileFilterIgnoreEndsWithList();
    abstract public Iterable<String> getDirectoryFilterIgnoreStartsWithList();
    abstract public Iterable<String> getDirectoryFilterIgnoreList();

    public RMIFileDirFilter getDirectoryFilter() {
        return this.directoryFilter;
    }

    public RMIFileDirFilter getFileFilter() {
        return this.fileFilter;
    }
}
